package com.example.springbootvuetest.controller;

import com.example.springbootvuetest.entity.Address;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springbootvuetest.base.Result;
import lombok.RequiredArgsConstructor;
import com.example.springbootvuetest.entity.OrderAddress;
import com.example.springbootvuetest.service.IOrderAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;


/**
 * <p>
 * controller
 * </p>
 *
 * @author shuoye
 * @since 2023-03-14
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Api(tags = "REST - ")
@RestController
@RequestMapping("/order-address")
public class OrderAddressController {
    private final IOrderAddressService service;

    @PostMapping("/add")
    @ApiOperation(value = "新增")
    public Result createOne(@RequestBody OrderAddress entity) {
        boolean flag = service.save(entity);
        return flag ? Result.success() : Result.error();
    }

    @GetMapping("/info")
    @ApiOperation(value = "获取订单地址")
    public Result getAddressInfo(@RequestParam("orderId") Integer orderId) {
        OrderAddress orderAddress = service.getById(orderId);
        return Result.success(orderAddress);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public Result update(@RequestBody OrderAddress entity) {
        boolean flag = service.updateById(entity);
        return flag ? Result.success() : Result.error();
    }
}